package com.owc.controller.common;

import com.owc.common.custom.annotation.Advice;
import com.owc.domain.BaseResult;
import com.owc.domain.PageVo;
import com.owc.domain.dto.*;
import com.owc.domain.vo.app.AuthCodeVo;
import com.owc.domain.vo.app.TokenVo;
import com.owc.domain.vo.app.VersionVo;
import com.owc.filter.content.SecurityContextHolder;
import com.owc.service.OwcService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * @Author xiaom
 * @Date 2019/12/2 14:46
 * @Version 1.0.0
 * @Description <公用路由>
 **/
@RestController
@RequestMapping("/common")
@Api(tags = "(NEW)OWC公共路由")
public class OwcController {

    private final OwcService owcService;

    public OwcController(OwcService owcService) {
        this.owcService = owcService;
    }

    /**
     * Send model phone verification code
     */
    @PostMapping(value = "sendCode")
    @ApiOperation("发送手机短信验证码")
    public BaseResult<Boolean> sendCode(@RequestBody @Valid AuthCodeVo authCodeVo){
        return BaseResult.success(owcService.sendCode(authCodeVo));
    }

    @PostMapping(value = "/getFindData")
    @ApiOperation("获取H5页面地址")
    public BaseResult<H5> getFindData(){
        return BaseResult.success(owcService.getH5Url());
    }

    /**
     * 获取最新版本
     */
    @PostMapping(value = "/getVersionInfo")
    @ApiOperation("获取服务器端最新版本")
    public BaseResult<VersionDTO> getVersionInfo(){
        return BaseResult.success(owcService.getVersionInfo());
    }

    /**
     * 获取提币须知
     */
    @PostMapping(value = "/getTransferNotice")
    @ApiOperation("获取提币须知")
    public BaseResult<TransferNotice> getTransferNotice(){
        return BaseResult.success(owcService.getTransferNotice());
    }

    /**
     * 获取手续费 + 提币须知 +
     * @return
     */
    @PostMapping(value = "/getCommonInfo")
    @ApiOperation("获取公共信息")
    public BaseResult<CommonInfo> getCommonInfo(@RequestBody @Valid TokenVo tokenVo){
        return BaseResult.success(owcService.getCommonInfo(tokenVo.getTokenId()));
    }

    @PostMapping(value = "/checkNotice")
    @ApiOperation("(APP-V2)检查是否存在新通知")
    public BaseResult<CheckNoticeDTO> checkNotice(){
        return BaseResult.success(owcService.checkNotice());
    }

    @PostMapping(value = "/getNotices")
    @ApiOperation("(APP-V2)获取公告列表")
    public BaseResult<NoticeDTO> getNotices(@RequestBody PageVo pageVo){
        return BaseResult.makePageBean(owcService.getNotices(pageVo.getPageIndex(),pageVo.getPageSize()));
    }

    @PostMapping(value = "/getOwcBasisInfo")
    @ApiOperation("(APP-V2)获取基础提示信息 (兑换说明/投资理财协议/风险提示)")
    public BaseResult<List<CommonInfoDTO>> getOwcBasisInfo(){
        return BaseResult.success(owcService.getOwcBasisInfo());
    }

}
